package test2;
import java.util.*;
class Card implements Comparable<Card>{
    public int rank;
    public String suit;
    public Card(int rank,String suit){
        this.rank=rank;
        this.suit=suit;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int compareTo(Card o) {
        return this.rank-o.rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}
class Student{
    public int age;
    public int score;
    public Student(int age, int score) {
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", score=" + score +
                '}';
    }
}
class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1,Student o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.score-o2.score;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Student student1 = new Student(1,89);
        Student student2 = new Student(2,29);
        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(student1, student2));

        ScoreComparator scoreComparator = new ScoreComparator();
        System.out.println(scoreComparator.compare(student1, student2));
    }
    public static void main2(String[] args) {
        PriorityQueue<Card> queue = new PriorityQueue<>();
        queue.offer(new Card(1,"♥"));
        queue.offer(new Card(2,"♥"));
        System.out.println(queue.poll());
        System.out.println(queue.poll());
    }
    public static void main1(String[] args) {
        Card c1 = new Card(12, "♠");
        Card c2 = new Card(41, "♠");
        Card c3 = c1;
        System.out.println(c1.equals(c2));
        System.out.println(c1.compareTo(c2));
    }
}
